package logic

import (
	"activity_srv/internal/dao"
	"context"
	"errors"

	"activity_srv/activity"
	"activity_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetGrouponProductDetailLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetGrouponProductDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetGrouponProductDetailLogic {
	return &GetGrouponProductDetailLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GetGrouponProductDetailLogic) GetGrouponProductDetail(in *activity.GetGrouponProductDetailRequest) (*activity.GetGrouponProductDetailResponse, error) {
	// todo: add your logic here and delete this line
	detail, err := dao.GetGrouponProductDetail(in)
	if err != nil {
		return nil, errors.New("获取拼团商品详情失败")
	}
	return &activity.GetGrouponProductDetailResponse{
		Id:            int64(detail.Id),
		ProductName:   detail.ProductName,
		ProductPrice:  float32(detail.ProductPrice),
		GroupPrice:    float32(detail.GroupPrice),
		MemberNum:     int64(detail.MemberNum),
		Status:        int64(detail.Status),
		ActivityStart: detail.ActivityStart.Format("2006-01-02 15:04:05"),
		ActivityEnd:   detail.ActivityEnd.Format("2006-01-02 15:04:05"),
		CoverImage:    detail.CoverImage,
		ProductStock:  int64(detail.ProductStock),
	}, nil
}
